<!DOCTYPE html>
<html>
<head>
    <title>管理员面板</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
    <header class="header">
        <div class="container header-content">
            <a href="{{ url_for('dashboard') }}" class="logo">云存储网盘</a>
            <div class="nav-links">
                <span>管理员: {{ session.email }}</span>
                <a href="{{ url_for('dashboard') }}">返回我的网盘</a>
                <a href="{{ url_for('logout') }}">退出登录</a>
            </div>
        </div>
    </header>
    
    <div class="container dashboard">
        {% with messages = get_flashed_messages(with_categories=true) %}
          {% if messages %}
            {% for category, message in messages %}
              <div class="flash-messages flash-{{ category }}">
                {{ message }}
              </div>
            {% endfor %}
          {% endif %}
        {% endwith %}
        
        <div class="admin-section">
            <h2><i class="fas fa-users-cog"></i> 用户管理</h2>
            <table class="admin-table">
                <tr>
                    <th>ID</th>
                    <th>邮箱</th>
                    <th>机器码</th>
                    <th>已用空间</th>
                    <th>总空间</th>
                    <th>使用率</th>
                    <th>注册时间</th>
                    <th>是否管理员</th>
                    <th>操作</th>
                </tr>
                {% for user in users %}
                <tr>
                    <td>{{ user.id }}</td>
                    <td>{{ user.email }}</td>
                    <td>{{ user.machine_code }}</td>
                    <td>{{ user.formatted_used }}</td>
                    <td>{{ user.formatted_limit }}</td>
                    <td>
                        <div class="storage-bar-container">
                            <div class="storage-bar 
                                {% if user.usage_percent >= 90 %}danger
                                {% elif user.usage_percent >= 80 %}warning
                                {% else %}normal{% endif %}" 
                                style="width: {{ user.usage_percent }}%"></div>
                        </div>
                        {{ user.usage_percent|round(1) }}%
                    </td>
                    <td>{{ user.created_at }}</td>
                    <td>{{ '是' if user.is_admin else '否' }}</td>
                    <td>
                        <form method="post">
                            <input type="hidden" name="user_id" value="{{ user.id }}">
                            <div style="display: flex; gap: 5px;">
                                <input type="number" name="storage_limit" step="0.1" min="0.1" 
                                       value="{{ (user.storage_limit / (1024**3))|round(1) }}" required
                                       style="width: 80px;">
                                <select name="size_unit" style="padding: 5px;">
                                    <option value="GB">GB</option>
                                    <option value="MB">MB</option>
                                    <option value="KB">KB</option>
                                </select>
                                <button type="submit" class="btn">设置</button>
                            </div>
                        </form>
                    </td>
                </tr>
                {% endfor %}
            </table>
        </div>
    </div>
</body>
</html>